import {
  Routes,
  Route,
  HashRouter,
  createBrowserRouter,
  RouterProvider,
} from "react-router-dom";
import { autoRoutes } from "./autos";
import { IS_HASH_ROUTER } from "@/config";
import { useEffect } from "react";
import { addCustomTone } from "@/utils/model";

export default function Models() {
  useEffect(() => {
    addCustomTone();
  }, []);

  function HashRoute() {
    return (
      <HashRouter>
        <Routes>
          {autoRoutes.map(({ path, element }) => (
            <Route key={path} path={path} element={element} />
          ))}
        </Routes>
      </HashRouter>
    );
  }

  function BrowserRoute() {
    const routes = createBrowserRouter(autoRoutes, {
      basename: import.meta.env.BASE_URL,
    });
    return <RouterProvider router={routes} />;
  }

  return IS_HASH_ROUTER ? <HashRoute /> : <BrowserRoute />;
}
